package com.ef.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.ef.constant.ELeadsDealType;
import com.ef.dao.CorpDealHistoryDao;
import com.ef.domain.Company;
import com.ef.domain.CorpDealHistory;
import com.ef.service.CorpDealHistoryService;

public class CorpDealHistoryServiceImpl extends BaseServiceImpl implements
		CorpDealHistoryService {

	private CorpDealHistoryDao corpDealHistoryDao;

	public List<CorpDealHistory> findByCompany(Company company) {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(CorpDealHistory.class);
		detachedCriteria.add(Restrictions.eq("company", company));
		detachedCriteria.addOrder(Order.desc("dealTime"));
		return corpDealHistoryDao.findAllByCriteria(detachedCriteria);
	}

	public List<CorpDealHistory> findByCompany(Company company, ELeadsDealType type) {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(CorpDealHistory.class);
		// detachedCriteria.createCriteria("leads").add(Restrictions.eq("id",
		// leads.getId()));
		detachedCriteria.add(Restrictions.eq("company", company));
		detachedCriteria.add(Restrictions.eq("type", type));
		detachedCriteria.addOrder(Order.desc("dealTime"));
		return corpDealHistoryDao.findAllByCriteria(detachedCriteria);
	}

	public void saveOrUpdate(CorpDealHistory entity) {
		corpDealHistoryDao.save(entity);
	}

	public CorpDealHistoryDao getCorpDealHistoryDao() {
		return corpDealHistoryDao;
	}

	public void setCorpDealHistoryDao(CorpDealHistoryDao corpDealHistoryDao) {
		this.corpDealHistoryDao = corpDealHistoryDao;
	}

 

}
